package com.dk.controller;

import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.pojo.Menu;
import com.dk.pojo.User;
import com.dk.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 * @author author
 * @since 2021-10-29
 */
@RestController
@RequestMapping("menuController")
@Api(value="菜单表接口文档")
public class MenuController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private IMenuService iMenuService;

    @ApiOperation(value = "菜单表详细数据展示")
    @GetMapping
    public Result findByID() {
         User user = (User) SecurityUtils.getSubject();
         List<Menu> menus =  iMenuService.findAll(user.getUid());
        return Result.bulid(ConstantEnum.SUCCESS).setResult(menus);
    }

    @ApiOperation(value = "菜单表的增加")
    @PostMapping
    public Result add(Menu menu){
        boolean save = iMenuService.save(menu);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(save);
    }

    @ApiOperation(value = "菜单表的修改")
    @PutMapping
    public Result update(Menu menu){
        boolean update = iMenuService.updateById(menu);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(update);
    }

    @ApiOperation(value = "菜单表的删除")
    @DeleteMapping
    public Result delete(String mid){
        boolean b = iMenuService.removeById(Long.parseLong(mid.trim()));
        return Result.bulid(ConstantEnum.SUCCESS).setResult(b);
    }
}
